package ca.animobile;

/*
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.client.calendar.CalendarQuery;
import com.google.gdata.client.calendar.CalendarService;
import com.google.gdata.data.DateTime;
import com.google.gdata.data.calendar.*;
import com.google.gdata.util.ServiceException;
import com.google.gdata.data.extensions.*;

import java.io.IOException;
import javax.servlet.http.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

public class CalendarServlet extends HttpServlet {

	// The base URL for a user's calendar metafeed (needs a username appended).
	private static final String METAFEED_URL_BASE = "http://www.google.com/calendar/feeds/";

	// The string to add to the user's metafeedUrl to access the allcalendars
	// feed.
	private static final String ALLCALENDARS_FEED_URL_SUFFIX = "/allcalendars/full";

	// The string to add to the user's metafeedUrl to access the owncalendars
	// feed.
	private static final String OWNCALENDARS_FEED_URL_SUFFIX = "/owncalendars/full";

	// The URL for the metafeed of the specified user.
	// (e.g. http://www.google.com/feeds/calendar/jdoe@gmail.com)
	private static URL metafeedUrl = null;

	// The URL for the allcalendars feed of the specified user.
	// (e.g.
	// http://www.googe.com/feeds/calendar/jdoe@gmail.com/allcalendars/full)
	private static URL allcalendarsFeedUrl = null;

	// The URL for the owncalendars feed of the specified user.
	// (e.g.
	// http://www.googe.com/feeds/calendar/jdoe@gmail.com/owncalendars/full)
	private static URL owncalendarsFeedUrl = null;

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {

		String userName = "animobilevet@gmail.com";
		String userPassword = "tristan1";

		// Create necessary URL objects
		try {
			metafeedUrl = new URL(METAFEED_URL_BASE + userName);
			allcalendarsFeedUrl = new URL(METAFEED_URL_BASE + userName
					+ ALLCALENDARS_FEED_URL_SUFFIX);
			owncalendarsFeedUrl = new URL(METAFEED_URL_BASE + userName
					+ OWNCALENDARS_FEED_URL_SUFFIX);
		} catch (MalformedURLException e) {
			// Bad URL
			System.err.println("Uh oh - you've got an invalid URL.");
			e.printStackTrace();
			return;
		}

		// Create CalendarService and authenticate using ClientLogin
		CalendarService service = new CalendarService("demo-CalendarFeedDemo-1");

		try {
			service.setUserCredentials(userName, userPassword);
		} catch (AuthenticationException e) {
			// Invalid credentials
			e.printStackTrace();
		}

		try {
			System.out.println("Calendars in metafeed");
			printUserCalendars(service, metafeedUrl);

			System.out.println("Calendars in allcalendars feed");
			printUserCalendars(service, allcalendarsFeedUrl);

			System.out.println("Calendars in owncalendars feed");
			printUserCalendars(service, owncalendarsFeedUrl);
		} catch (IOException e) {
			// Communications error
			System.err
					.println("There was a problem communicating with the service.");
			e.printStackTrace();
		} catch (ServiceException e) {
			// Server side error
			System.err
					.println("The server had a problem handling your request.");
			e.printStackTrace();
		}

		// Get events in availability Calendar -------------------------------
		// Limit events to this month
		URL eventURL = new URL(metafeedUrl + "/private/full");

//		getMonth(, DateTime.parseDateTime("2010-08-31T00:00:00"));
		
		CalendarQuery myQuery = new CalendarQuery(eventURL);
		myQuery.setMinimumStartTime(DateTime.parseDateTime("2010-08-01T00:00:00"));
		myQuery.setMaximumStartTime(DateTime.parseDateTime("2010-08-31T00:00:00"));
		
		try {
			CalendarEventFeed myFeed = service.getFeed(eventURL,
					CalendarEventFeed.class);

			List<CalendarEventEntry> l = myFeed.getEntries();
			for (CalendarEventEntry e : l) {
				java.util.List<When> when = e.getTimes();
				System.out.println("Entries length = " + when.size());

				Recurrence rec = e.getRecurrence();
				if (rec != null) {
					System.out.println("Recurence = " + rec.getValue() + "\n");
				}

				System.out.println(e.getTitle().getPlainText());
			}

		} catch (ServiceException e) {
			System.err
					.println("The server had a problem handling Event Requests.");
			e.printStackTrace();
		}

	}

	/**
	 * Prints the titles of calendars in the feed specified by the given URL.
	 * 
	 * @param service
	 *            An authenticated CalendarService object.
	 * @param feedUrl
	 *            The URL of a calendar feed to retrieve.
	 * @throws IOException
	 *             If there is a problem communicating with the server.
	 * @throws ServiceException
	 *             If the service is unable to handle the request.
	private static void printUserCalendars(CalendarService service, URL feedUrl)
			throws IOException, ServiceException {

		// Send the request and receive the response:
		CalendarFeed resultFeed = service.getFeed(feedUrl, CalendarFeed.class);

		// Print the title of each calendar
		for (int i = 0; i < resultFeed.getEntries().size(); i++) {
			CalendarEntry entry = resultFeed.getEntries().get(i);
			System.out.println("\t" + entry.getTitle().getPlainText());
		}
	}

	private static void getMonth(DateTime start, DateTime end) {
		
	}

}
*/
